<template>

    <div>
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li>
                    <span>版本管理</span>
                </li>
            </ul>
        </div>

        <el-form :model="version">
            <el-row :gutter="20">
                <label class="input-label">版本号</label>
                <el-input v-model="version.versionNo" placeholder="版本号"></el-input>

                <label class="input-label">发布人</label>
                <el-select v-model="version.userId" placeholder="请选择">
                    <el-option
                            v-for="item in userlist.records"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                    </el-option>
                </el-select>

                <!--<label class="input-label">发布人</label>-->
                <!--<el-input v-model="version.userId"></el-input>-->

                <!--<label class="input-label">开始时间</label>-->
                <!--<el-date-picker-->
                        <!--type="date"-->
                        <!--placeholder="选择日期"-->
                        <!--v-model="version.startTime"-->

                <!--&gt;-->
                <!--</el-date-picker>-->


                <!--<label class="input-label">结束时间</label>-->
                <!--<el-date-picker-->
                        <!--type="date"-->
                        <!--placeholder="选择日期"-->
                        <!--v-model="version.endTime"-->

                <!--&gt;-->
                <!--</el-date-picker>-->


                <el-button type="primary" v-on:click="queryVersion()" style="margin-left:10px">查询  <i
                        class="el-icon-search"></i></el-button>
                <el-button type="primary" v-on:click="createVersion()" style="float:right">新建 <i
                        class="el-icon-plus"></i></el-button>

            </el-row>
        </el-form>

        <el-table
                :data="tableData"
                style="width: 100%">
            <el-table-column
                    type="index"
                    label="序号"
                    width="100"
            >
            </el-table-column>

            <el-table-column
                    prop="versionNo"
                    label="版本号">
            </el-table-column>
            <el-table-column
                    label="发布时间"
                    inline-template
            >
                <template>
                    <span v-tranTime='row.createTime'></span>
                </template>
            </el-table-column>
            <el-table-column
                    prop="userName"
                    label="发布人"
            >
            </el-table-column>


            <el-table-column
                    inline-template
                    prop="address"
                    width="150"
                    label="操作">
                <template>
                    <el-button type="primary" size="small" @click="detailVersion(row)">修改</el-button>
                    <el-button size="small" type="danger" @click="open2(row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div style="text-align:right;" v-if="version.pageSize>1">

            <div class="block">

                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :page-size="version.pageSize"
                        layout="total, prev, pager, next"
                        :total="total">
                </el-pagination>
            </div>
        </div>

    </div>

</template>

<script>
    import {VersionSrv} from './version.service';
    import { UserSrv } from './../user/user.service';

    export default {
        data() {
            return {
                userlist:'',
                version: {
                    userId:'',
                    versionNo:'',
                    beginTime:'',
                    endTime:'',
                    pageIndex:1,
                    pageSize:15,
                },
                userId:'',
                versionNo:'',
                beginTime:'',
                endTime:'',
                pageIndex:'',
                pageSize:'',
                token:'',
                isopen: true,
                visible: false,
                tableData: [],
                total:0,
            }
        },
        methods: {
            goPage(path) {
                this.$router.push(path);
            },
            handleSizeChange(val){

            },
            handleCurrentChange(val){
                this.version.pageIndex=val;
                this.queryVersion();
            },
            queryVersion() {
                VersionSrv.list(this.version).then((result) =>{
                    console.log(result.data);
                    if(result.code === 0){
                        this.tableData = result.data.records;//records
                        this.total=result.data.totalRecords;
                    }
                })

            },
            getUserList() {

                UserSrv.getUserList({ pageIndex:1,pageSize:999,}).then((result) => {
                    if(result.code === 0) {
                        this.userlist = result.data;
                    }
                })
            },
            createVersion(row) {

                this.$router.push({name: 'versionCreate'})
            },
            detailVersion(row) {
                this.$router.push({name: 'versiondetail', params: {id: row.id}})
            },
            deleteVersion(row) {
                VersionSrv.deleteByAPP(row.id).then((result) =>{
                    if(result.code === 0){
                        this.queryVersion();
//                        this.tableData = result.data.records;
//                        this.total=result.data.totalRecords;
                    }
                })
            },
            open2(row) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
//                    this.$message({
//                        type: 'success',
//                        message: '删除成功!'
//                    });
                    this.deleteVersion(row);



                }).catch(() => {
//                    this.$message({
//                        type: 'info',
//                        message: '已取消删除'
//                    });
                });
            },


        },
        created(){


//            console.log(this.version)

            this.queryVersion();
            this.getUserList();
//            this.tableData =VersionSrv.list(this.version);
        },
        mounted() {

        }
    }
</script>

<style scoped>

    .input-label {
        float: left;
        text-align: center;
        height: 36px;
        line-height: 36px;
        margin-bottom: 10px;
        width: 60px;

    }

    .el-row {
        margin: 10px 0 !important;
    }

    .el-input {
        float: left;
        margin: 0 5px;
        width: 140px;

    }

    .form-button-search .el-button {

        float: right;
        margin-left: 10px;
    }

</style>
